package vn.sunnet.backviet01.game.coloa.AuLac;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.util.MathUtils;

public class Arrow extends Sprite{
	protected boolean isCriptical = false;
	
	protected float stun = 0;
	protected boolean isStun = false;
	
	protected float headX;
	protected float headY;
	
	protected float damage = 0;
	protected int id = -1;
	
	protected final static float PI = 3.1416f;
	protected static float SIN = 0;
	protected static float COS = 0;
	
	public Arrow(float pX, float pY, TextureRegion pTextureRegion) {
		super(pX, pY, pTextureRegion);
	}

	public void onManagedUpdate(float pSecondsElapsed) {
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	public float getHeadX() {
		float width = this.getWidth() - 15;
		
		float dx = width * COS;

		this.headX = this.getX() + dx - SIN * 8;
		
		return this.headX;
	}
	
	public float getHeadY() {
		float width = this.getWidth() - 15;
		float dy = (SIN * width + 8 * COS);
		this.headY = this.getY() + dy;
		return this.headY;
	}
	
	public void setRotation(float pRotation) {
		super.setRotation(pRotation);
		SIN = (float) (Math.sin(PI * pRotation / 180));
		COS = (float) (Math.cos(PI * pRotation / 180));
	}

	public float getDamage() {
		return damage;
	}

	public void setDamage(float damage) {
		this.damage = damage;
	}

	public void setDamage(float damage, int id, int level) {
		switch (id) {
		case -1:
			this.damage = damage;
			break;
		case 0:
			this.damage = damage * (1.1f + 0.05f * level);
			break;
		case 2:
			this.damage = damage;
			this.setStunEnemy(0.5f + (level - 1) * 0.25f);
			break;
		
		case 4:
			this.damage = damage + (level * 10) + 10;
			setStunEnemy(1);
			break;
			
		case 6:
			setCriptical(level * 10);
			if (this.isCriptical) this.damage = damage * 3;
			else this.damage = damage + level * 10;
			break;
		case 8:
			setStunEnemy(1.75f + level * 0.25f);
			this.damage = damage + 50;
		default:
			break;
		}
	}
	
	public void setStunEnemy(float stun) {
		this.stun = stun;
		isStun = true;
	}
	
	public boolean isStun() {
		return isStun;
	}
	
	public long getStun() {
		return (long)(stun * 1000);
	}
	
	public boolean isCriptical() {
		return isCriptical;
	}
	
	public void setCriptical(int percent) {
		int  k = MathUtils.random(1, 100);
		
		if (k <= percent)
			isCriptical = true;
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void resetInforArrow() {
		stun = 0;
		isStun = false;
		isCriptical = false;
		damage = 0;
		id = -1;
	}
	
}
